﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public partial class HairGen
{
    bool GetMousePos(out float length)
    {
        length = 0f;
        Vector3 prev = Vector3.zero; // 如果鼠标位置在（0,0）长度会出错
        posList = new List<Vector3>();
        foreach (var p in pos2dList)
        {
            var pHit = InputEvents.I.SVToRayHit(p);
            if (pHit == Vector3.zero)
            {
                var dist = cam.WorldToScreenPoint(focus.position).z;
                pHit = cam.ScreenToWorldPoint(p) + dist * cam.transform.forward;
            }
            posList.Add(pHit);
            if (prev != Vector3.zero)
                length += Vector3.Distance(pHit, prev);
            prev = pHit;
        }
        /// 直接取头尾的支线距离 not iter solution
        // length = Vector3.Distance(posList[0], posList[posList.Count - 1]);
        return !(posList.Count < 2);
    }
}
